/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.store.StoreManager;
/*     */ import com.zimbra.cs.store.external.ExternalBlobConsistencyChecker;
/*     */ import com.zimbra.cs.store.external.ExternalStoreManager;
/*     */ import com.zimbra.cs.store.file.BlobConsistencyChecker;
/*     */ import com.zimbra.cs.store.file.BlobConsistencyChecker.Results;
/*     */ import com.zimbra.cs.store.file.FileBlobStore;
/*     */ import com.zimbra.cs.volume.Volume;
/*     */ import com.zimbra.cs.volume.VolumeManager;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class CheckBlobConsistency
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  43 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  44 */     checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
/*     */     
/*     */ 
/*     */ 
/*  48 */     List<Integer> mailboxIds = new ArrayList();
/*  49 */     List<Element> mboxElementList = request.listElements("mbox");
/*  50 */     if (mboxElementList.isEmpty())
/*     */     {
/*  52 */       for (int mboxId : MailboxManager.getInstance().getMailboxIds()) {
/*  53 */         mailboxIds.add(Integer.valueOf(mboxId));
/*     */       }
/*     */       
/*     */     } else {
/*  57 */       for (Element mboxEl : mboxElementList) {
/*  58 */         Mailbox mbox = MailboxManager.getInstance().getMailboxById((int)mboxEl.getAttributeLong("id"));
/*  59 */         mailboxIds.add(Integer.valueOf(mbox.getId()));
/*     */       }
/*     */     }
/*     */     
/*  63 */     boolean checkSize = request.getAttributeBool("checkSize", true);
/*  64 */     boolean reportUsedBlobs = request.getAttributeBool("reportUsedBlobs", false);
/*     */     
/*     */ 
/*  67 */     Element response = zsc.createElement(AdminConstants.CHECK_BLOB_CONSISTENCY_RESPONSE);
/*     */     
/*  69 */     StoreManager sm = StoreManager.getInstance();
/*  70 */     Iterator i$; if ((sm instanceof ExternalStoreManager))
/*     */     {
/*  72 */       for (i$ = mailboxIds.iterator(); i$.hasNext();) { int mboxId = ((Integer)i$.next()).intValue();
/*  73 */         ExternalBlobConsistencyChecker checker = new ExternalBlobConsistencyChecker();
/*  74 */         BlobConsistencyChecker.Results results = checker.check(null, mboxId, checkSize, reportUsedBlobs);
/*  75 */         if ((results.hasInconsistency()) || (reportUsedBlobs)) {
/*  76 */           Element mboxEl = response.addElement("mbox").addAttribute("id", mboxId);
/*  77 */           results.toElement(mboxEl);
/*     */         } } } else { List<Short> volumeIds;
/*     */       Iterator i$;
/*  80 */       if ((sm instanceof FileBlobStore))
/*     */       {
/*     */ 
/*  83 */         volumeIds = new ArrayList();
/*  84 */         List<Element> volumeElementList = request.listElements("volume");
/*  85 */         if (volumeElementList.isEmpty())
/*     */         {
/*  87 */           for (Volume vol : VolumeManager.getInstance().getAllVolumes()) {
/*  88 */             switch (vol.getType()) {
/*     */             case 1: 
/*     */             case 2: 
/*  91 */               volumeIds.add(Short.valueOf(vol.getId()));
/*     */             
/*     */             }
/*     */             
/*     */           }
/*     */         } else {
/*  97 */           for (Element volumeEl : volumeElementList) {
/*  98 */             short volumeId = (short)(int)volumeEl.getAttributeLong("id");
/*  99 */             Volume vol = VolumeManager.getInstance().getVolume(volumeId);
/* 100 */             if (vol.getType() == 10) {
/* 101 */               throw ServiceException.INVALID_REQUEST("Index volume " + volumeId + " is not supported", null);
/*     */             }
/* 103 */             volumeIds.add(Short.valueOf(volumeId));
/*     */           }
/*     */         }
/*     */         
/*     */ 
/* 108 */         for (i$ = mailboxIds.iterator(); i$.hasNext();) { int mboxId = ((Integer)i$.next()).intValue();
/* 109 */           BlobConsistencyChecker checker = new BlobConsistencyChecker();
/* 110 */           BlobConsistencyChecker.Results results = checker.check(volumeIds, mboxId, checkSize, reportUsedBlobs);
/* 111 */           if ((results.hasInconsistency()) || (reportUsedBlobs)) {
/* 112 */             Element mboxEl = response.addElement("mbox").addAttribute("id", mboxId);
/* 113 */             results.toElement(mboxEl);
/*     */           }
/*     */         }
/*     */       }
/*     */       else {
/* 118 */         throw ServiceException.INVALID_REQUEST(sm.getClass().getName() + " is not supported", null);
/*     */       } }
/* 120 */     return response;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 125 */     notes.add("Only system admins are allowed.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CheckBlobConsistency.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */